﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BrainTechLLC;

namespace UserInterface
{
	public partial class TypeEditor : UserControl
	{
		protected string _type;
		[Bindable(BindableSupport.Yes)]
		public string SelectedType
		{
			get { return _type; }
			set
			{
				_type = value;
				UpdateBindings();
			}
		}

		public void UpdateBindings()
		{
			if (_type != null)
			{
				string braintechType = "BrainTechLLC." + _type;
				if (cboTypes.Items == null || cboTypes.Items.Count == 0)
				{
					cboTypes.Items.Add(string.Empty);
					cboTypes.Items.AddRange(TypeProvider.GetInstance()._typeLookup.Keys.ToArray());
				}
				if (string.IsNullOrEmpty(_type))
				{
					cboTypes.SelectedIndex = 0;
				}
				else
				{
					for (int n = 0; n < cboTypes.Items.Count; n++)
					{
						if (cboTypes.Items[n].ToString().IndexOf(_type, StringComparison.OrdinalIgnoreCase) == 0 ||
							 cboTypes.Items[n].ToString().IndexOf(braintechType, StringComparison.OrdinalIgnoreCase) == 0)
						{
							cboTypes.SelectedIndex = n;
							break;
						}
					}
				}
			}
		}

		public TypeEditor()
		{
			InitializeComponent();
		}
	}
}
